<!DOCTYPE html>
<html height100 xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <div th:replace="authority/common/currency/head"></div>
</head>
<body class="childrenBody">
<!--/*@thymesVar id="changePasswordUrl" type="java.lang.String"*/-->
<form th:action="@{${changePasswordUrl}}" class="layui-form layui-row changePwd" onsubmit="return false">
    <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
                <!--/*@thymesVar id="userName" type="java.lang.String"*/-->
                <input type="text" th:value="${userName}" disabled class="layui-input layui-disabled">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">旧密码</label>
            <div class="layui-input-block">
                <input type="password" value="" name="oldPassword" placeholder="请输入旧密码"
                       lay-verify="required" class="layui-input pwd">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">新密码</label>
            <div class="layui-input-block">
                <input type="password" value="" name="password" placeholder="请输入新密码" lay-verify="required|newPassword"
                       class="layui-input pwd">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">确认密码</label>
            <div class="layui-input-block">
                <input type="password" value="" name="confirmPassword" placeholder="请确认密码"
                       lay-verify="required|confirmPassword" class="layui-input pwd">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="change-submit">立即修改</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </div>
</form>
<div th:replace="authority/common/currency/footer"></div>
<script th:src="@{/authority/js/jquery.base64.js}"></script>
<script>
    layui.use(['form', 'lutil'], function () {
        var form = layui.form,
            lutil = layui.lutil;

        //添加验证规则
        form.verify({
            newPassword: function (value, elem) {
                if (value.length < 6) {
                    return "密码长度不能小于6位";
                }
            },
            confirmPassword: function (value, elem) {
                if (!new RegExp($("input[name=password]").val()).test(value)) {
                    return "两次输入密码不一致，请重新输入！";
                }
            }
        })
        form.on('submit(change-submit)', function (formData) {
            $.each(formData.field, function (i, e) {
                formData.field[i] = $.base64.encode($.base64.encode(e));
            });
            ajaxRequestByCsrf($(formData.form).attr('action'), formData.field, function (res) {
                lutil.success_msg(res.message);
                location.href = res.data.action;
            });
            return false;
        });
    })
</script>
</body>
</html>